
import requests
import time
from util.getheaders import get_headers_init_referer
from util.time_stamp import get_time_stamp
import json

url = f'https://product.weather.com.cn/alarm/grepalarm_cn.php?_={get_time_stamp()}'
response = requests.get(url, headers=get_headers_init_referer("https://www.weather.com.cn/"))
content = response.content.decode('utf-8')[14:-1]
json_data = json.loads(content)
# time.sleep(1)
for item in json_data['data']:
    print(item)
    detail_url = f'https://product.weather.com.cn/alarm/webdata/{item[1]}?_={get_time_stamp()}'
    detail_res = requests.get(detail_url, headers=get_headers_init_referer("https://www.weather.com.cn/"))
    detail_data = json.loads(detail_res.content.decode('utf-8')[14:])
    print(detail_data)

print("爬虫结束......")
